<template>
	<view class="container">
		<u-search v-model="queryParams.piTitle" :show-action="true" actionText="搜索" :animation="true" @search="handleSearch" @clear="handleSearch"></u-search>
		<u-gap height="15" bgColor="#f5f5f5"></u-gap>
		<view class="guide_content">
			<view class="guide_content_item" v-for="item in guideList" :key="item.piId" @click="handleDetail(item)">
				<view class="guide_content_item_left">
					<view class="guide_content_item_left_title">
						{{ item.piTitle }}
					</view>
					<view class="guide_content_item_left_time">
						{{ item.publishDate }}
					</view>
				</view>
				<view class="guide_content_item_right">
					<u-image src="https://jsgl.zfcxjw.cq.gov.cn:28082/prod-api/profile/upload/2025/06/17/bszn-bg_20250617105611A983.png" radius="10" width="200rpx" height="160rpx" mode="aspectFill"></u-image>
				</view>
			</view>
			<u-empty
				v-if="guideList.length == 0"
				text="暂无数据"
				style="width: 100%;"
				:icon="emptyIcon"
			></u-empty>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad, onReachBottom  } from "@dcloudio/uni-app";
import { getGuide } from '@/api/qss/index.js'
import emptyIcon from "@/pagesC/static/images/ndata.png"

/* 办事指南 */
const guideList = ref([])
const total = ref(0)
const queryParams = ref({
	pageNum: 1,
	pageSize: 10,
	piType:1,
	status:0,
	piTitle:''
})
function getGuideList(){
	getGuide(queryParams.value).then(res=>{
		if(res.code == 200){
		    guideList.value = guideList.value.concat(res.rows)
		}
	})
}

/* 搜索 */
function handleSearch(){
	queryParams.value.pageNum = 1
	guideList.value = []
	getGuideList()
}


/* 详情 */
function handleDetail(item){
	uni.navigateTo({
		url: '/pagesC/guide/detail?id=' + item.piId
	})
}

onLoad((option)=>{
	getGuideList()
})

//触底加载
onReachBottom(res=>{
	console.log('触底了')
	queryParams.value.pageNum++
	if((queryParams.value.pageNum * queryParams.value.pageSize)  > total.value){
		uni.showToast({
			title: '没有更多了',
			icon: 'none'
		})
	}else{
		getGuideList()
	}
})

</script>

<style lang="scss" scoped>
.container {
    width: 100%;
	::v-deep .u-search{
		width: 100%;
	    padding: 10rpx 40rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		background-color: #fff;
		box-sizing: border-box;
	}
	::v-deep .u-gap{
		width: 100%;
		position: fixed;
		top: 82rpx;
		left: 0;
		z-index: 998;
	}
}
/* 办事指南 */
.guide_content{
	width: 100%;
	padding: 20rpx 40rpx 40rpx 40rpx;
	box-sizing: border-box;
	margin-top: 120rpx ;
	&_item{
		width: 100%;
		height: 200rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 2rpx solid #eaeaea;

		&_left{
			flex: 1;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 16rpx 0;
			box-sizing: border-box;
			&_title{
				font-size: 30rpx;
				font-weight: 600;
				color: #101010;
				//超出2行溢出隐藏
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}
			&_time{
				font-size: 28rpx;
				color: #999;
			}
		}
		&_right{
			margin-left: 20rpx;
			width: 200rpx;
		}
		&:first-child {
			border-top:unset;
		}
	}
}
</style>